// pages/order/orderFeedback/orderFeedback.js
var api = require("../../../api.js"),
    app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        feedback: "",
        order_no: '',
        carnum:'',
        focus:false
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.setData({
            order_no: options.order_no
        })
      // 获取优惠券
      if (options.uid) {
        app.shareCouponsMessage(options.uid)
      }
    },
    // bindTextAreaBlur 获取提交的值
    bindTextAreaBlur: function(e) {
        console.log(e.detail.value);
        this.setData({
            feedback: e.detail.value
        });
    },
    bindButtonTap(){
      this.setData({
        focus: true
      })
    },
        // bindTextAreaBlur 获取提交的值
        bindcarnum: function(e) {
          console.log(e.detail.value);
          this.setData({
              carnum: e.detail.value
          });
      },
    // orderFeedbackHandler 提交订单反馈意见
    orderFeedbackHandler: function() {
        var that = this;
        if (this.data.feedback === null || this.data.feedback === "" || this.data.carnum==="") {
            wx.showToast({
                title: '请输入订单意见',
                icon: "none"
            })
        } else {
            wx.showModal({
                title: '订单反馈',
                content: '是否提交',
                success: function(res) {
                  
                    if (res.confirm) {
                      wx.showLoading({})
                        app.request({
                            url: api.order_feedback.order_feedback,
                            method: 'post',
                            data: {
                                order_no: that.data.order_no,
                                carnum:that.data.carnum,
                                msg: that.data.feedback
                            },
                            success: function(rs) {
                              wx.hideLoading()
                                if (rs.code == 1) {
                                    wx.showToast({
                                        title: '提交成功',
                                    })
                                  wx.navigateBack({
                                    delta: 1
                                  })
                                    // wx.redirectTo({
                                    //     url: '../orderDetail/orderDetail',
                                    // })
                                } else {
                                    wx.showToast({
                                        title:rs.msg,
                                        icon: "none"
                                    })
                                  wx.navigateBack({
                                    delta: 1
                                  })
                                }
                            }
                        })
                    }
                },
                fail: function() {
                    wx.showToast({
                        title: '提交失败',
                        icon: "none"
                    })
                }
            })
        }
    },
  // 用户分享
  onShareAppMessage: function () {
    let title = app.shareAppMessage().title;
    let imageUrl = app.shareAppMessage().imageUrl;
    let desc = app.shareAppMessage().desc;
    let path = app.shareAppMessage().path;
    // console.log(app.shareAppMessage())
    return {
      title: title,
      imageUrl: imageUrl,
      desc: desc,
      path: path,
    }
  },
})